package com.mes.basicdata.dao;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.mes.basicdata.dao.iface.IClassInformationDao;
import com.mes.basicdata.domain.ClassInformation;
import com.mes.common.dao.BasicDao;

@Repository
public class ClassInformationDao extends BasicDao<ClassInformation> 
	implements IClassInformationDao{

	@Override
	public List<ClassInformation> getChildClassInofs(Map<String, Object> params) {
		String hql = "from ClassInformation where sortId = 'Sort1' and parentClassId = :parentClassId and classAttribute = :classAttribute";
		return this.query(hql, params);
	}

	@Override
	public String getClassNameByClassId(String classId, String sortId) {
		String className = "";
		Session session = this.getSessionFactory().getCurrentSession();
		String hql = "select className from ClassInformation where classId = ? and sortId = ?";
		Query query = session.createQuery(hql);
		query.setString(0, classId);
		query.setString(1, sortId);
		Object obj = query.uniqueResult();
		if (obj != null)
			className = (String) obj;
		return className;
	}

}
